package com.itheima.exception;

import com.itheima.comon.Code;
import com.itheima.comon.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description:
 * @Version: V1.0
 */

@RestControllerAdvice
@Component
public class MyExceptionAdvice extends RuntimeException {

    @ExceptionHandler(BusinessException.class)
    public Result BizException(BusinessException ex){

        return ex.getResult();
    }
    @ExceptionHandler(Exception.class)
    public Result BizException(Exception ex) {
        // 记录日志 发短信 ...
        System.out.println(ex);
        // 给用户提示友好信息
        return new Result(Code.USER_ERROR, "您的网络有问题，请稍后重试！");
    }
}
